package com.springboot.reidssort.service.impl;

import com.springboot.reidssort.service.ChapterService;
import com.springboot.reidssort.util.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ChapterServiceImpl implements ChapterService {


    @Autowired
    private RedisTemplate<String, Test> redisTemplate;

    private static final String ORDERED_LIST_KEY = "orderedListp";

    // 添加元素到有序列表
    @Override
    public void addToSortedSet() {
        // 创建多个 Person 对象
        List<Test> people = Arrays.asList(
                new Test("Alice", 25),
                new Test("Bob", 30),
                new Test("Charlie", 35)
        );

        redisTemplate.opsForList().rightPushAll(ORDERED_LIST_KEY, people);
    }

    // 获取有序列表的元素
    @Override
    public List<Test> getSortedSet() {
        return redisTemplate.opsForList().range(ORDERED_LIST_KEY, 0, -1);  // 获取全部列表
    }




}
